﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mvc.XForms.Actions;

namespace Mvc.XForms.Controls.Settings {
	public class SelectSettings {
		public ISelect Select { get; private set; }

		public SelectSettings(ISelect select) {
			Select = select;
		}

		public SelectSettings Label(string label) {
			Select.Label = label;
			return this;
		}

		public SelectSettings Help(string help) {
			Select.Help = help;
			return this;
		}

		public SelectSettings Hint(string hint) {
			Select.Hint = hint;
			return this;
		}

		public SelectSettings Appearance(Appearance appearance) {
			Select.Appearance = appearance;
			return this;
		}

		public SelectSettings ReadOnly() {
			return ReadOnly(true);
		}

		public SelectSettings ReadOnly(bool readOnly) {
			Select.ReadOnly = readOnly;
			if (readOnly)
				Select.CssClass.Add("readonly");
			return this;
		}

		public SelectSettings Required() {
			return Required(true);
		}

		public SelectSettings Required(bool required) {
			Select.Required = required;
			if (required)
				Select.CssClass.Add("required");
			return this;
		}

		public SelectSettings ID(string clientID) {
			Select.ClientID = clientID;
			return this;
		}

		public SelectSettings CssClass(string cssClass) {
			Select.CssClass.Add(cssClass);
			return this;
		}

		public SelectSettings Action(XFormEvent xformsEvent, string jsFunction) {
			var action = new ActionAction() {
				Event = xformsEvent,
				JSFunction = jsFunction
			};
			Select.Actions.Add(action);
			return this;
		}

		public override string ToString() {
			return Select.ValidateThenRender();
		}
	}
}
